<?php
require('../kernel/config.php');
if(!isset($_GET['q']))setError();
$s_imgfile = PATH_ABS.'/resource/'.$_GET['q']; 
if(is_file($s_imgfile)){
	if(!extension_loaded('gd'))setError();
	$a_imagen = getimagesize($s_imgfile);
	if($a_imagen['mime'] == 'image/jpeg'){
		$r_img = imagecreatefromjpeg($s_imgfile);
	}elseif($a_imagen['mime'] == 'image/gif'){
		$r_img = imagecreatefromgif($s_imgfile);
	}elseif($a_imagen['mime'] == 'image/png'){
		$r_img = imagecreatefrompng($s_imgfile);
	}
	
	$i_width = $a_imagen[0];
	$i_height = $a_imagen[1];
	$i_maxwidth = isset($_GET['maxw'])?(int)$_GET['maxw']:100;
	$i_maxwidth = $i_maxwidth > $i_width?$i_width:$i_maxwidth;
	$i_por = round(($i_maxwidth * 100) / $i_width);
	$i_newwidth=$i_maxwidth;
	$i_newheight = round(($i_height * $i_por) / 100);
	
	$r_newimg = imagecreatetruecolor($i_newwidth, $i_newheight);
	$r_colour = imagecolorallocate($r_img, 255, 255, 255);
    imagefill($r_img, 0, 0, $r_colour);
	imagecopyresampled($r_newimg, $r_img, 0, 0, 0, 0, $i_newwidth, $i_newheight, $i_width, $i_height);
	header('Content-type: image/jpeg');
	imagejpeg($r_newimg, NULL, 80);
	exit();
}else setError();

function setError(){
	header('Content-type: image/gif');
	readfile(PATH_ABS.'/admin/images/na.gif');
	exit();
}


 
?>
